package com.hitqz.robot.biz.flow.component.agv;

import com.hitqz.robot.api.business.enums.RobotOtherCommandEnum;
import com.hitqz.robot.biz.flow.util.LiteFlowUtil;
import com.hitqz.robot.driver.parent.RobotDriverService;
import com.hitqz.robot.common.core.util.R;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author xupkun
 * @date 2024/6/15
 */
@Slf4j
@LiteflowComponent(value = "LiftDownJackStatus", name = "[轮对/轮轴]-顶升下降")
@AllArgsConstructor
public class LiftDownJackStatus extends NodeComponent {
    private final RobotDriverService robotDriverService;


    @Override
    public void process() throws Exception {
        LiteFlowUtil.checkInterruptFlag();
        robotDriverService.executeOtherCommand(RobotOtherCommandEnum.JACKING_DOWN,null);
        TimeUnit.SECONDS.sleep(8);
        R result = robotDriverService.executeOtherCommand(RobotOtherCommandEnum.JACKING_STATUS,null);
        int  jackStatus = (int) result.getData();
        int time = 0;
        while (3 != jackStatus) {
            result = robotDriverService.executeOtherCommand(RobotOtherCommandEnum.JACKING_STATUS,null);
            jackStatus = (int) result.getData();
            //if (time > 50) {
            //    time = 0;
            //    robotDriverService.executeOtherCommand(RobotOtherCommandEnum.JACKING_DOWN,null);
            //}
            LiteFlowUtil.checkInterruptFlag();
            time ++;
        }
        log.info("lifter down finished");
    }
}
